<template>
  <view>
    <my-search @myClick="gotoSearch()"></my-search>
    <view class="title">
      <uni-section title="十二月" type="circle" bgdcolor="#F0F8ff00"></uni-section>
    </view>

    <unicloud-db v-slot:default="{data, loading, error, options}" :where="where12" collection="expense">
      <view v-if="error">{{error.message}}</view>
      <view v-else>
        <uni-list class="expense-list" v-for="item in data" :key="item._id">
          <uni-list-item :title="item.name" :note="item.time" showArrow :show-extra-icon="true"
            :extra-icon="icons[item.type]" :rightText="item.price">
          </uni-list-item>
        </uni-list>
      </view>
    </unicloud-db>
    <view class="title">
      <uni-section title="十一月" type="circle" bgdcolor="transparent"></uni-section>
    </view>
    <unicloud-db v-slot:default="{data, loading, error, options}" :where="where11" collection="expense">
      <view v-if="error">{{error.message}}</view>
      <view v-else>
        <uni-list class="expense-list" v-for="item in data" :key="item._id">
          <uni-list-item :title="item.name" :note="item.time" showArrow :show-extra-icon="true"
            :extra-icon="icons[item.type]" :rightText="item.price"></uni-list-item>
        </uni-list>
      </view>
    </unicloud-db>

  </view>
</template>

<script>
  export default {
    data() {
      return {
        time: 'hhhh',
        kw: ['11月', '12月'],
        icons: {
          eat: {
            color: '#D4F2E7',
            size: '22',
            type: 'fire-filled'
          },
          study: {
            color: '#D4F2E7',
            size: '22',
            type: 'wallet-filled'
          },
          happy: {
            color: '#D4F2E7',
            size: '22',
            type: 'heart-filled'
          },
          buy: {
            color: '#D4F2E7',
            size: '22',
            type: 'cart-filled'
          }
        },
      };
    },
    computed: {
      where11() {
        return `${new RegExp(this.kw[0], 'i')}.test(time)` // 使用计算属性得到完整where
      },
      where12() {
        return `${new RegExp(this.kw[1], 'i')}.test(time)` // 使用计算属性得到完整where
      }
    },
    methods: {
      gotoSearch() {
        uni.navigateTo({
          url: '/subpkg/search/search'
          // success: res => {},
          // fail: () => {},
          // complete: () => {}          
        });
      }
    }

  }
</script>

<style lang="scss">

</style>
